<!--# 
layout("/layout/default.html",{"menu":[nameSpace,"user_admin"],"breadcrumbs":[{"name":"用户列表",url:"user/list"},{"name":(obj.data.user==null?"添加用户":"编辑用户")}]}){ 
 #-->
<div class="space-4"></div>
<div class="row">
	<div class="col-md-8 col-md-offset-2 col-sm-12">
		<div class="panel panel-info">
			<div class="panel-heading">
				<h3 class="panel-title">${obj.data.user==null ? "添加用户":"编辑用户"}</h3>
			</div>
			<div class="panel-body">
				<form id="addUserForm" class="cmxform form-horizontal adminex-form" novalidate="novalidate">
					<div class="form-group ">
						<label for="用户名" class="control-label col-lg-3">用户名(登录名) : </label>
						<div class="col-lg-9">
							<input class="form-control" type="text" placeholder="请输入登录名" name="name" data-type='required' data-error='请输入登录名' value="${obj.data.user.name!}" ${obj.data.user==null? "":"disabled"} />
						</div>
					</div>
					<div class="form-group ">
						<label class="control-label col-lg-3"> 真实姓名 : </label>
						<div class="col-lg-9">
							<input class="form-control" type="text" placeholder="请输入用户真实姓名" name="realName" data-type='required' data-error='请输入用户真实姓名' value="${obj.data.user.realName!}">
						</div>
					</div>
					<!--# 
						if(obj.data.user == null){
					#-->
					<div class="form-group ">
						<label class="control-label col-lg-3"> 密码 : </label>
						<div class="col-lg-9">
							<input class="form-control" type="password" placeholder="请输入密码" name="password" data-type='password' data-error='密码只能是字母和数字,长度不少于6位'>
						</div>
					</div>
					<div class="form-group ">
						<label class="control-label col-lg-3"> 确认密码 : </label>
						<div class="col-lg-9">
							<input class="form-control" type="password" placeholder="请再次输入密码" name="rePassword" data-type='password' data-error='密码只能是字母和数字,长度不少于6位'>
						</div>
					</div>
					<!--# }#-->
					<div class="form-group ">
						<label class="control-label col-lg-3"> 电话 : </label>
						<div class="col-lg-9">
							<input class="form-control" type="text" placeholder="请输入电话号码" name="phone" data-type='phone' data-error='请输入正确的电话号码' value="${obj.data.user.phone!}">
						</div>
					</div>
					<div class="form-group ">
						<label class="control-label col-lg-3"> 邮箱 : </label>
						<div class="col-lg-9">
							<input class="form-control" type="text" placeholder="请输入邮箱地址" name="email" data-type='email' data-error='请输入正确的邮箱地址' value="${obj.data.user.email!}">
						</div>
					</div>
					<input type="hidden" id="id" name="id" value="${obj.data.user.id!}">
					<div class="form-group ">
						<label class="control-label col-lg-3"> 用户状态 : </label>
						<div class="col-lg-9">
							<input type="hidden" name="status" value="${obj.data.user.status!}"> <label> <input name="statusSwitch" class="ace ace-switch ace-switch-4 btn-flat"
								type="checkbox" ${obj.data.user.status! == "ACTIVED" ? "checked":""} /> <span class="lbl"></span></label>
						</div>
					</div>
					<div class="pull-right" style="margin-right: 45px">
						<button type="button" class="btn btn-sm btn-primary" onclick="save(this)">
							<i class="fa fa-save"></i> 提交
						</button>
						<a href="${base}/user/list" class="btn btn-sm btn-default"> <i class="fa fa-undo"></i> 返回
						</a>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
	function save(btn) {
		$("input[name='status']").val($("input[name='statusSwitch']")[0].checked ? "ACTIVED" : "DISABLED");//将开关状态刷回表单进行提交
		if ($('#addUserForm').find('input').validation()) {//验证表单
			if ($('#id').val()) {
				$.post(getRootPath() + '/user/edit', $('#addUserForm').serialize(), function(result) {
					if (result.operationState == 'SUCCESS') {
						location.href = getRootPath() + "/user/list";
					} else {
						validationFail(result.data.reason, btn);
					}
				}, 'json');
			} else if ($("input[name='password']").val() === $("input[name='rePassword']").val()) {
				$.post(getRootPath() + '/user/add', $('#addUserForm').serialize(), function(result) {
					if (result.operationState == 'SUCCESS') {
						location.href = getRootPath() + "/user/list";
					} else {
						validationFail(result.data.reason, btn);
					}
				}, 'json');
			} else {
				validationFail("两次输入的密码不一致", $("input[name='rePassword']"));
			}
		}
	}
</script>
<!--# } #-->